/* 和用户相关的接口信息 */
import request from './request.js'

/* 获取列表条数 */
export async function getUserListCounter() {
    let url = '/staff';
    return await request.get(url);
}

/* 用户列表相关的接口 */
export async function getUserList({ page, limit }) {
    let url = '/staff';
    return await request.get(url, {
        params: {
            _page: page,
            _limit: limit
        }
    });
}

/* 用户删除接口 */
export async function deleteUser(id) {
    let url = '/staff' + '/' + id;
    await request.delete(url);
}

/* 用户状态修改接口 */
export async function updateStatus(id, status) {
    let url = '/staff' + '/' + id;
    await request.patch(url, { status });
}

/* 用户修改信息接口 */
export async function updateMsg(id, name, sex, department, position, date, tel, email, address) {
    let url = '/staff' + '/' + id;
    if (name) {
        await request.patch(url, { name });
    }
    if (sex) {
        await request.patch(url, { sex });
    }
    if (department) {
        await request.patch(url, { department });
    }
    if (position) {
        await request.patch(url, { position });
    }
    if (date) {
        await request.patch(url, { date });
    }
    if (tel) {
        await request.patch(url, { tel });
    }
    if (email) {
        await request.patch(url, { email });
    }
    if (address) {
        await request.patch(url, { address });
    }
}

/* 添加用户信息接口 */
export async function addUser({ name, sex, department, position, date, tel, email, address, status }) {
    let url = '/staff';
    await request.post(url, { name, sex, department, position, date, tel, email, address, status });
}

/* 查询员工信息 */
export async function findeUserMsg(value, keywords) {
    let url = '/staff';
    if (value == "name") {
        return await request.get(url, {
            params: {
                name_like: keywords
            }
        });
    }
    if (value == "sex") {
        return await request.get(url, {
            params: {
                sex_like: keywords
            }
        });
    }
    if (value == "department") {
        return await request.get(url, {
            params: {
                department_like: keywords
            }
        });
    }
    if (value == "position") {
        return await request.get(url, {
            params: {
                position_like: keywords
            }
        });
    }
    if (value == "date") {
        return await request.get(url, {
            params: {
                date_like: keywords
            }
        });
    }
    if (value == "tel") {
        return await request.get(url, {
            params: {
                tel_like: keywords
            }
        });
    }
    if (value == "email") {
        return await request.get(url, {
            params: {
                email_like: keywords
            }
        });
    }
    if (value == "address") {
        return await request.get(url, {
            params: {
                address_like: keywords
            }
        });
    }
    if (value == "status") {
        return await request.get(url, {
            params: {
                status_like: keywords
            }
        });
    }
}